<?php
namespace app\mall\admin;
use app\admin\controller\Admin;
use app\common\builder\ZBuilder;
use think\Db;

function result($data){
	$res['code'] = '0';
	$res['msg'] = '请求成功';
	$res['data'] = $data;
	return json($res);
}

function result_fail($msg,$code){
	$res['code'] = $code ? $code : '1';
	$res['msg'] = $msg ? $msg : '请求失败';
}

/**
 * 后台模块
 */
class Index extends Admin
{
	public function index(){
		return $this->fetch();
	}
	
	public function add() {
		$list_city = ['gz' => '广州', 'sh' => '上海', 'fz' => '福州'];
		return ZBuilder::make('form')
		->setPageTitle("标题")
		->setPageTips("这是提示信息","info","top")
		->addBtn('<button type="button" class="btn btn-success">额外按钮</button>')
		->setBtnTitle('submit','确定')
		->addText('title','输入框')
		->addCheckbox('city','选择城市','',$list_city,['gz','fz'])
		->addRadio('sex','单选框','',$list_city,'sh')
		->addDate('time','日期','请选择','','yyyy-mm-dd')
		->addWangeditor('content','wang编辑器')
		->fetch();
	}
	
	public function add2() {
		$list_city = ['gz' => '广州', 'sh' => '上海', 'fz' => '福州'];
		return ZBuilder::make('form')
		->addFormItems([
			['text','title','输入框'],
			['radio','sex','单选框','',$list_city,'sh'],
			['text:6','title1','输入框1'],
			['text:6','title2','输入框2'],
		])
		->setUrl(url('save'))
		->fetch();
	}
	
	public function save() {
		$post = request()->post();
		$data['title'] = $post['title'];
		$data['sex'] = $post['sex'];
		$data['title1'] = $post['title1'];
		$data['title2'] = $post['title2'];
		
		$res = Db::name('form_info')->insert($data);
		if($res){
			return result($res);
		}
	}
	
	public function list1() {
		$data = Db::name("form_info")->select();
		return ZBuilder::make('table')
		->addColumns([
			['__INDEX__', '#'],
			['id','ID'],
			['title','输入框'],
			['title1','输入框1'],
			['title2','输入框2'],
			['sex','单选框']
		])
		->addTopButton('add') // 添加顶部按钮
		->addTopButton('delete') // 添加顶部按钮
		->setRowList($data)
		->fetch();
	}
	
	public function add3(){
		return ZBuilder::make('form')
		->addFormItems([
			["text","ss","lab1"]
		])
		->fetch();
	}
}